package com.zlb.app.common.strategy.impl;

import com.zlb.app.common.properties.MinioProperties;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;

/**
 * @Desc Minio上传策略
 * @Author zWX1367238
 * @Date 2024-08-16 11:04:48
 **/

@Service("minioUploadStrategyImpl")
public class MinioUploadStrategyImpl extends AbstractUploadStrategyImpl {

    @Autowired
    private MinioProperties minioProperties;

    @Override
    public Boolean exists(String filePath) {
        boolean exist = true;
        // try {
        //     getMinioClient()
        //         .statObject(StatObjectArgs.builder().bucket(minioProperties.getBucketName()).object(filePath).build());
        // } catch (Exception e) {
        //     exist = false;
        // }
        return exist;
    }

    @SneakyThrows
    @Override
    public void upload(String path, String fileName, InputStream inputStream) {
        // getMinioClient().putObject(
        //     PutObjectArgs.builder().bucket(minioProperties.getBucketName()).object(path + fileName).stream(
        //                      inputStream, inputStream.available(), -1)
        //                  .build());
    }

    @Override
    public String getFileAccessUrl(String filePath) {
        return minioProperties.getUrl()+ minioProperties.getBucketName()+ "/" + filePath;
    }

    // private MinioClient getMinioClient() {
    //     return MinioClient.builder()
    //                       .endpoint(minioProperties.getEndpoint())
    //                       .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
    //                       .build();
    // }

}